﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FileSystem.Models;

namespace FileSystem.Services.IServices {
    /// <summary>
    /// 访问控制信息存储接口
    /// </summary>
    public interface IAccessControlInfoStorage {
        /// <summary>
        /// 初始化访问控制信息存储
        /// </summary>
        Task InitializeAsync();

        /// <summary>
        /// 访问控制信息存储是否已经初始化
        /// </summary>
        bool IsInitialized();

        /// <summary>
        /// 增加访问控制信息
        /// </summary>
        /// <param name="accessControlInfo">要添加的访问控制信息</param>
        Task AddAsync(AccessControlInfo accessControlInfo);

        /// <summary>
        /// 删除访问控制信息
        /// </summary>
        /// <param name="accessControlInfo">要删除的访问控制信息</param>
        Task RemoveAsync(AccessControlInfo accessControlInfo);

        /// <summary>
        /// 修改属性
        /// </summary>
        /// <param name="accessControlInfo">访问控制信息</param>
        /// <param name="property">属性</param>
        /// <param name="newContent">新值</param>
        Task ModifyProperty(AccessControlInfo accessControlInfo,
            AccessControlInfoConst.Property property, string newContent);

        /// <summary>
        /// 修改属性
        /// </summary>
        /// <param name="accessControlInfo">访问控制信息</param>
        /// <param name="property">属性</param>
        /// <param name="newContent">新值</param>
        Task ModifyProperty(AccessControlInfo accessControlInfo,
            AccessControlInfoConst.Property property, bool newContent);

        /// <summary>
        /// 根据目录项名、路径和用户名获得用户对该目录项的访问控制信息
        /// </summary>
        /// <param name="dirItemName">目录项名</param>
        /// <param name="location">路径</param>
        /// <param name="userName">用户名</param>
        Task<AccessControlInfo> GetAccessControlInfo(string dirItemName,string location,string userName);

        /// <summary>
        /// 获得所有访问控制信息
        /// </summary>]
        Task<IList<AccessControlInfo>> GetAccessControlInfos();
    }

    /// <summary>
    /// 访问控制信息存储常量
    /// </summary>
    public static class AccessControlInfoStorageConstants
    {
        /// <summary>
        /// 默认的访问控制信息数据库版本号。
        /// </summary>
        public const int DefaultVersion = 0;

        /// <summary>
        /// 访问控制信息数据库版本号。
        /// </summary>
        public const int Version = 1;

        /// <summary>
        /// 访问控制信息数据库版本号键。
        /// </summary>
        public const string VersionKey = nameof(AccessControlInfoStorageConstants) +
            "." + nameof(Version);
    }
}